package org.gpslw.controller;


import org.geotools.api.feature.simple.SimpleFeature;
import org.gpslw.service.ShapeFileService;
import org.gpslw.util.DataStoreUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


import java.util.List;

@RestController
@RequestMapping("/shp")
public class ShpController {

    @Autowired
    private ShapeFileService shapeFileService;
    /**
     * 获取shp数据
     * @param shpPath = data/datastore/nyc/poi.shp
     * @return
     */
    @GetMapping("/list")
    public List<SimpleFeature> getShpData(@RequestParam("shpPath") String shpPath){
        return DataStoreUtils.getShpData(shpPath);
    }

    /**
     * 将shp数据导入到postgis
     * @param shpPath
     * @param tableName
     * @return
     */
    @PostMapping("/shpToPostGis")
    public String shpToPostGis(@RequestParam("shpPath") String shpPath, @RequestParam("tableName") String tableName){
        shapeFileService.shpToPostGis(shpPath);
        return "success";
    }

    /**
     * 将shp数据导入到postgis
     * @param shpPath
     * @param tableName
     * @return
     */
    @PostMapping("/shpToPostGisV2")
    public String shpToPostGisV2(@RequestParam("shpPath") String shpPath, @RequestParam("tableName") String tableName){
        shapeFileService.shpToPostGisV2(shpPath);
        return "success";
    }

}
